package whf.framework.resource.thread;

import whf.framework.log.Log;
import whf.framework.log.LogFactory;

/**
 * 永不超时的线程任务
 * 
 * @author king
 * @create 2008-1-23 下午04:41:57
 * 
 */
public abstract class UnTimeoutablePoolableThread extends AbstractPoolableThread {
	protected Log log = LogFactory.getLog(this.getClass());
	private long interval = 1000 * 10;

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.resource.thread.AbstractPoolableThread#isTimeout()
	 */
	@Override
	public final boolean isTimeout() {
		return false;
	}

	public void setInterval(long interval) {
		if (interval > 0)
			this.interval = interval;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.resource.thread.AbstractHandle#handleWhenTimeout()
	 */
	@Override
	public final void run() {
		while (true) {
			try {
				this.handle();
			} catch (Exception e) {
				log.error(this, e);
			}
			try {
				Thread.sleep(interval);
			} catch (Exception e) {
				// ignore
			}
		} // end while
	} // end run

	public abstract void handle() throws Exception;
}